package com.mars.pay.controller;

import com.mars.pay.dto.WxLoginDTO;
import com.mars.pay.service.WechatMiniAppService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 微信小程序相关接口
 */
@RestController
@RequestMapping("/api/wechat/miniapp")
@RequiredArgsConstructor
public class WechatMiniAppController {

    private final WechatMiniAppService wechatMiniAppService;
    
    /**
     * 获取OpenID
     */
    @PostMapping("/openid")
    public Map<String, String> getOpenId(@RequestBody WxLoginDTO loginDTO) {
        String openId = wechatMiniAppService.getOpenId(loginDTO.getCode());
        
        Map<String, String> result = new HashMap<>();
        result.put("openid", openId);
        return result;
    }
} 